<?php
header("Content-type: application/xhtml+xml");

require_once('../lib/Smarty/Smarty.class.php');
require_once('../lib/People.php');
require_once('../lib/Schedule.php');
require_once('../lib/Util.php');
require_once('../lib/lib.mobile.php');
require_once('../lib/Config.php');

$data   = make_page(array_merge($_GET, $_POST));
$smarty = new Smarty();
$smarty->assign($data);
$smarty->display($data['error_code'] ? 'error.tmpl' : 'remove_hima.tmpl');

function make_page ($params) {
    $data = array('error_code' => 0);

    if (!validate_signature($params)) {
        $data['error_code'] = 1;
        return $data;
    }

    $smarty = new Smarty();

    $user = $params['opensocial_owner_id'];
    $schedule_id = $params['schedule_id'];

    $schedule = new Schedule($schedule_id);
    if (!$schedule || !$schedule->id) {
        $data['error_code'] = 1;
        return $data;
    }

    if ($schedule->member_id != $user) {
        $data['error_code'] = 1;
        return $data;
    }

    $result = $schedule->delete();

    $data['current_page'] = '';
    $data['owner_id']     = $user;
    $data['result']       = $result;
    $data['url_prefix'] = URL_PREFIX;

    $data['analytics']    = '<img src="' . googleAnalyticsGetImageUrl() . '" />'; // for google analytics

    return $data;
}

?>
